import { createApp } from 'vue';
import App from './App.vue';

// 引入路由
import Router from './routers/index';

// 引入Vant
import Vant from 'vant';

// 引入Vant样式
import 'vant/lib/index.css';

// 引入Cookie
import VueCookies from 'vue3-cookies';

// 引入工具函数
import Tools from './tools/tools';

// 引入请求服务
import Request from './services/request';

const app = createApp(App)
.use(Router)
.use(Vant)
.use(VueCookies)
.use(Tools)
.use(Request)
.mount('#app');

// 全局前置路由守卫
Router.beforeEach(async (to,from,next) => {
    // 获取是否登录属性
    let IsLogin = to.meta.IsLogin === true ? true : false;

    if(IsLogin === true)
    {

        let result = await app.$login();

        if(result.code === 0)
        {
            app.$warnNotify(result.msg);

            app.$cookies.remove('business');

            next('/business/base/login');

            return false;
        }

        next();
    }else{
        // 放行 直接去目标路由
        next();
    }
})